package com.jt.www.common.service.impl;

import com.jt.www.common.service.HeaderConfigureService;
import com.jt.www.dao.mapper.headerconfigure.ProductHeaderConfigureMapper;
import com.jt.www.model.headerconfigure.ProductHeaderConfigureEntity;
import com.jt.www.model.reps.GenericListResponse;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class HeaderConfigureServiceImpl implements HeaderConfigureService {

    @Autowired
    private ProductHeaderConfigureMapper productHeaderConfigureMapper;

    /**
     * 根据产品编码查询列
     *
     * @param productCode
     * @param identiFication
     * @return
     * @throws Exception
     */
    @Override
    public ResponseEntity selectHeaderByProductCode(String productCode, String identiFication) throws Exception {

        // 如果productCode为空，则查询默认配置
        Map<String, Object> map = new HashMap<>();
        if (StringUtils.isNotBlank(productCode)) {
            map.put("productCode", productCode);
        } else {
            map.put("productCode", "default");
        }
        map.put("identiFication", identiFication);

        List<ProductHeaderConfigureEntity> list = productHeaderConfigureMapper.selectHeaderByProductCode(map);

        //将结果返回
        return GenericListResponse.listAndCount(list, list.size());
    }
}
